package com.corpgovernment.travelstandard.impl;

import com.corpgovernment.api.travelstandard.service.IMbTravelstandFlightTimeService;
import com.corpgovernment.api.travelstandard.vo.MbTravelstandFlightTimeVo;
import com.corpgovernment.common.base.AbstractBaseService;
import com.corpgovernment.common.base.Page;
import com.corpgovernment.common.utils.ListUtils;
import com.corpgovernment.common.utils.ObjectUtils;
import com.corpgovernment.common.utils.PageUtils;
import com.corpgovernment.travelstandard.entity.db.MbTravelstandFlightTime;
import com.corpgovernment.travelstandard.mapper.MbTravelstandFlightTimeMapper;
import com.ctrip.corp.obt.shard.context.PageContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MbTravelstandFlightTimeService extends AbstractBaseService implements IMbTravelstandFlightTimeService {

    @Autowired
    private MbTravelstandFlightTimeMapper mbTravelstandFlightTimeMapper;

    @Override
    public void insert(MbTravelstandFlightTimeVo model) {
        mbTravelstandFlightTimeMapper.insertSelective(ObjectUtils.copyProperties(model, MbTravelstandFlightTime.class));
    }

    @Override
    public int delete(Long id) {
        return mbTravelstandFlightTimeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(MbTravelstandFlightTimeVo model) {
        return mbTravelstandFlightTimeMapper.updateByPrimaryKeySelective(ObjectUtils.copyProperties(model,MbTravelstandFlightTime.class));
    }

    @Override
    public MbTravelstandFlightTimeVo get(Long id) {
        return ObjectUtils.copyProperties(mbTravelstandFlightTimeMapper.selectByPrimaryKey(id),MbTravelstandFlightTimeVo.class);
    }

    @Override
    public List<MbTravelstandFlightTimeVo> list(MbTravelstandFlightTimeVo model) {
        return ListUtils.copyList(
                mbTravelstandFlightTimeMapper.list(ObjectUtils.copyProperties(model,MbTravelstandFlightTime.class)),
                MbTravelstandFlightTimeVo.class
        );
    }

    @Override
    public int deleteByTsId(Long tsId) {
        return mbTravelstandFlightTimeMapper.deleteByTsId(tsId);
    }

    @Override
    public Page page(MbTravelstandFlightTimeVo model) {
        MbTravelstandFlightTime param = ObjectUtils.copyProperties(model,MbTravelstandFlightTime.class);
        PageContext.startPage(model.getPageNum(),model.getPageSize());
        List<MbTravelstandFlightTime> list = mbTravelstandFlightTimeMapper.list(param);
        return PageUtils.optPageBy(list, MbTravelstandFlightTimeVo.class);
    }
}
